# -*- coding: utf-8 -*-
import urllib
import urllib.request
import urllib.parse
import http
import threading
from html.parser import HTMLParser
import io
import os
import time
import socket
from datetime import datetime
import gzip
import re
import base64
from pyDes import *

# 转化为36进制
def to36(val):
    val=int(val)
    if val==0:
        return '0'
    res=[]
    while val>0:
        m=val%36
        val=int(val/36)
        if 0<=m<=9:
            res.append(chr(m-0+ord('0')))
        else:
            res.append(chr(m-10+ord('a')))
    res.reverse()
    return ''.join(res)

# 加密程序
def func_e(c,a):
    c,a=int(c),int(a)
    res=None
    if c<a:
        res=''
    else:
        res=func_e(int(c/a),a)
    c=c%a
    if c>35:
        res+=chr(c+29)
    else:
        res+=to36(c)
    return res

def dec():
    key_code='''x6f|x70|x65|x64|window|x6d|x72|x63|__cr|x74'.split('|')'''
    a,c=10,10
    c=c-1
    decode={}
    while c>=0:
        idx=func_e(c,a)
        decode[idx]=key_code[c] or idx
        c-=1
    en='''4["\\1\\6\\0\\5\\1\\9"](8["\\3\\2\\7\\0\\3\\2"])'''
    def rep(m):
        res=m.group()
        try:
            res=decode[res]
        except:
            pass
        return res
    dec_str=re.subn(r'\w+',rep,en)
    print(dec_str[0])

def dec2(en_path):
    de_path=[]
    for c in en_path:
        de_path.append(chr(ord(c)-4))
    print(''.join(de_path))   

def dec3():
    def to23(val):
        val=int(val)
        if val==0:
            return '0'
        res=[]
        while val>0:
            m=val%23
            val=int(val/23)
            if 0<=m<=9:
                res.append(chr(m-0+ord('0')))
            else:
                res.append(chr(m-10+ord('a')))
        res.reverse()
        return ''.join(res)
    def func_u(n):
        return to23(n)
    r="|CryptoJS|t|enc|parse|decrypted|substring|Utf8||mode|function|Base64|decryptDES|var|DES|decrypt|ciphertext|ECB|padding|pad|Pkcs7|return|toString".split("|")
    f={}
    for i in range(0,23):
        f[func_u(i)]=r[i] or func_u(i)
    def rep(m):
        return f[m.group()]
    en="a c(2){d 5=1.e.f({g:1.3.b.4(2.6(8))},1.3.7.4(2.6(0,8)),{9:1.9.h,i:1.j.k});l 5.m(1.3.7)}"
    dec_func_content=re.subn(r'\w+',rep,en)[0]
    print(dec_func_content)
    with open('dec.js','w') as f:
        f.write(dec_func_content)
    print('over')

def pydes_test(src):
    Des_Key = "BHC#@*UM" # Key
    Des_IV = "\x22\x33\x35\x81\xBC\x38\x5A\xE7" # 自定IV向量
    k=des(Des_Key,CBC,Des_IV,pad=None,padmode=PAD_PKCS5)
    es=k.encrypt(src)
    return base64.b64encode(es)

def zero_prefix(val,lens=4):
    val=int(val)
    digits=[]
    for i in range(0,lens):
        digits.append(str(val%10))
        val=int(val/10)
    digits.reverse()
    return ''.join(digits)

if __name__=='__main__':
    for i in range(0,51):
        print(zero_prefix(i))
